      SUBROUTINE MEMORY
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C     Subroutine MEMORY (de)allocates memory space. Address pointers
C     relative to V in blank common are calculated.
C     Total available space is determined by IBLC.
C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
      PARAMETER (ILEN=10)
      PARAMETER (IBLC=1000)
      INTEGER V
      COMMON V(IBLC)
      COMMON /MEMRY/ NR,MAX,IF(ILEN)
C      BOOLEAN IERR
C
      DATA NR,MAX,IF /2*0, ILEN*1/
C      DATA IERR/R"CM"/
      DATA IERR/999/
C
      ENTRY ADDCM(I,N)
      V(1)=0
      IF (NR.LT.ILEN) THEN
        IF (NR.NE.0) THEN
          I=IF(NR)+V(IF(NR))+1
        ELSE
          I=2
        ENDIF
        NR=NR+1
        IF(NR)=I
C---------- INDEX OF FIRST WORD
        IF (I+N.GT.IBLC) CALL ABORT(
     +  'F',3,'SUBR.ADDCM','IBLC',I+N,IERR)
        V(I)=N
C---------- FIRST WORD = REQUIRED LENGTH
        I=I+1
C---------- AVAILABLE TO MAIN: SECOND WORD FF.
        DO 10 J=I,I+N-1
C        V(J)=O"17770000000000000000"
        V(J)=0.
   10   CONTINUE
C---------- PRESET TO INDEFINITE
C
      ELSE
        CALL ABORT('F',4,
     +  'TOO MANY CALLS TO SUBR.ADDCM, CHANGE ILEN',
     +  'ILEN',ILEN,IERR)
      ENDIF
      RETURN
C
      ENTRY SHRCM(I,N)
      V(I-1)=V(I-1)-N
      RETURN
C
      ENTRY FREECM(I)
      DO 20 J=1,NR
      IF(IF(J).EQ.I-1) THEN
        IF(J)=1
        IF (J.EQ.NR) NR=NR-1
        RETURN
      ENDIF
   20 CONTINUE
C
      ENTRY MAPCM(NT)
      K=LOCATE(V)
      WRITE (NT,30) NR,MAX,K,LENCM()-K,IF,(V(IF(J)),J=1,ILEN)
   30 FORMAT(//' BLANK COMMON MAP:',I5,' MAPPED,',I5,
     +' UNMAPPED BLOCKS,  START ADDRESS BLANK COMMON',I7,
     +',  RELATIVE END OF FL AT',I7/
     +' ARRAY INDICES',10I7/' BLOCK LENGTHS',10I7/)
      RETURN
C
      ENTRY CMMOP4
      RETURN
      END
C
C
C
